// miniprogram/pages/work4/index.js
Page({
  data: {
    src: 'images/c.png',
    list: [{
        name: 'C',
        active: true,
        src: 'images/c.png'
      },
      {
        name: 'D',
        active: false,
        src: 'images/d.png'
      },
      {
        name: 'E',
        active: false,
        src: 'images/e.png'
      },
      {
        name: 'F',
        active: false,
        src: 'images/f.png'
      },
      {
        name: 'G',
        active: false,
        src: 'images/g.png'
      },
      {
        name: 'A',
        active: false,
        src: 'images/a.png'
      },
      {
        name: 'B',
        active: false,
        src: 'images/b.png'
      },
    ]
  },
  click(ele) {
    const id = ele.currentTarget.dataset.id,
      e = this.data.list[id]

    for (const v of this.data.list) {
      v.active = false
    }
    e.active = true

    this.setData({
      src: e.src,
      list: this.data.list
    })
  }
})